Skip to content

Managed type thread safety#2322

Merged
andrei-marinica merged 10 commits intofeat/mdropfrom
threading
Mar 30, 2026
Merged

Managed type thread safety#2322
andrei-marinica merged 10 commits intofeat/mdropfrom
threading

Conversation

@andrei-marinica
Copy link
Copy Markdown
Contributor

@andrei-marinica andrei-marinica commented Mar 27, 2026

Pull request overview

Adds a dedicated handle wrapper for StaticApi to improve managed-type thread-safety semantics (thread-local handle space), plus new tooling binaries to validate threading behavior and benchmark managed-type memory retention in the scenario environment.

Changes:

  • Introduce StaticApiHandle and switch StaticApiBackend::HandleType from RawHandle to the new wrapper type.
  • Adjust managed-type raw-handle extraction to use HandleConstraints::get_raw_handle() (supporting non-i32 handle wrapper types).
  • Add managed-mem-bench binaries for leak/memory lifecycle benchmarking and multi-threaded behavior checks.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

Contract comparison - from 35e26ae to 5ac255d

Path                                                                                             size                  has-allocator                     has-format
large-storage.wasm 1656 false None
send-tx-repeat.wasm 1292 false None
queue-repeat.wasm 5540 false None
linked-list-repeat.wasm 6842 false without message
map-repeat.wasm 7367 false without message
set-repeat.wasm 6515 false None
vec-repeat.wasm 4876 false None
single-value-repeat.wasm 4257 false None
str-repeat-mb-builder-cached.wasm 1109 false without message
str-repeat.wasm 2733 false without message
str-repeat-mb-builder-basic.wasm 757 false None
multiversx-wegld-swap-sc.wasm 4492 false None
multiversx-price-aggregator-sc.wasm 17910 false without message
crypto-zombies.wasm 9255 false without message
empty.wasm 244 false None
digital-cash.wasm 9845 false None
token-release.wasm 6977 false without message
bonding-curve-contract.wasm 14132 false None
crowdfunding.wasm 3557 false None
crypto-bubbles.wasm 2541 false None
nft-minter.wasm 9725 false without message
proxy-pause.wasm 4148 false None
nft-storage-prepay.wasm 2606 false None
multisig.wasm 13442 false without message
multisig-full.wasm 15130 false without message
multisig-view.wasm 5590 false None
adder.wasm 699 false None
esdt-transfer-with-fee.wasm 7502 false without message
nft-subscription.wasm 8840 false without message
kitty-genetic-alg.wasm 3494 false without message
kitty-ownership.wasm 12965 false without message
kitty-auction.wasm 9411 false without message
fractional-nfts.wasm 8306 false without message
order-book-factory.wasm 3401 false None
order-book-pair.wasm 14229 false None
ping-pong-egld.wasm 6397 false None
seed-nft-minter.wasm 14443 false without message
rewards-distribution.wasm 9605 false without message
factorial.wasm 579 false None
check-pause.wasm 1260 false None
lottery-esdt.wasm 10578 false without message
erc20.wasm 1870 false None
erc1155.wasm 12023 false without message
crowdfunding-erc20.wasm 4910 false without message
erc1155-marketplace.wasm 10602 false without message
erc721.wasm 2232 false None
erc1155-user-mock.wasm 1229 false None
lottery-erc20.wasm 12893 false without message
use-module.wasm 32741 false without message
use-module-view.wasm 736 false None
std-contract.wasm 3469 true without message
abi-tester.wasm 8607 true without message
abi-tester-ev.wasm 760 false None
rust-testing-framework-tester.wasm 8608 false None
rust-snippets-generator-test.wasm 4710 false None
exchange-features.wasm 1514 false None
formatted-message-features.wasm 3600 false without message
big-float-features.wasm 6373 false without message
multi-contract-example-feature.wasm 680 false None
multi-contract-features.wasm 681 false None
multi-contract-alt-impl.wasm 353 false None
multi-contract-features-view.wasm 1113 false None
esdt-system-sc-mock.wasm 4623 false None
child.wasm 3982 false without message
parent.wasm 1979 false None
vault-upgrade.wasm 708 false None
vault.wasm 9035 false None
recursive-caller.wasm 5163 false without message
transfer-role-features.wasm 8667 false without message
forwarder-blind.wasm 14098 false without message
forwarder-raw-init-sync-call.wasm 2938 false None
forwarder-raw-init-async-call.wasm 2357 false None
forwarder-raw.wasm 13193 false None
forwarder-legacy.wasm 33668 false without message
first-contract.wasm 3433 false None
second-contract.wasm 1158 false None
forwarder-queue-promises.wasm 13533 false without message
forwarder-queue.wasm 12908 false without message
proxy-test-second.wasm 2329 false without message
forwarder.wasm 49178 false without message
local-esdt-and-nft.wasm 12568 false without message
proxy-test-first.wasm 5719 false without message
builtin-func-features.wasm 3820 false None
scenario-tester.wasm 1374 false None
forbidden-opcodes.wasm 842 false None
alloc-mem-fail.wasm 17819 true without message
alloc-features.wasm 23267 false without message
alloc-mem-leaking.wasm 23424 false without message
payable-features.wasm 5872 false None
basic-features-small-int-bug.wasm 824 false None
basic-features-storage-bytes.wasm 541 false None
basic-features.wasm 86384 false without message
panic-message-features.wasm 13036 false with message
panic-message-std.wasm 16074 false with message

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a dedicated handle wrapper for StaticApi to improve managed-type thread-safety semantics (thread-local handle space), plus new tooling binaries to validate threading behavior and benchmark managed-type memory retention in the scenario environment.

Changes:

  • Introduce StaticApiHandle and switch StaticApiBackend::HandleType from RawHandle to the new wrapper type.
  • Adjust managed-type raw-handle extraction to use HandleConstraints::get_raw_handle() (supporting non-i32 handle wrapper types).
  • Add managed-mem-bench binaries for leak/memory lifecycle benchmarking and multi-threaded behavior checks.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/managed-mem-bench/src/bench_threading.rs New multi-thread validation binary for StaticApi handle isolation/reset/round-trip patterns.
tools/managed-mem-bench/src/bench_leak.rs New allocation-tracking benchmark binary for managed-type lifecycle memory behavior.
tools/managed-mem-bench/Cargo.toml Registers the two new binaries.
framework/scenario/src/api/impl_vh/static_api_handle.rs Adds StaticApiHandle wrapper implementing HandleConstraints.
framework/scenario/src/api/impl_vh/static_api.rs Switches StaticApiBackend to use StaticApiHandle.
framework/scenario/src/api/impl_vh/debug_handle.rs Attempts to further restrict DebugHandle cross-thread usage via phantom marker.
framework/scenario/src/api/impl_vh.rs Wires in new modules/exports (static_api_handle, renamed debug handle module).
framework/scenario/src/api.rs Re-exports StaticApiHandle from scenario API.
framework/base/src/types/managed/managed_type_trait.rs Updates ManagedType::get_raw_handle() to use HandleConstraints API (wrapper-friendly).
framework/scenario/tests/derive_managed_vec_item_biguint_test.rs Imports HandleConstraints to use to_be_bytes() on handle type.
framework/scenario/tests/derive_managed_vec_item_esdt_token_payment_test.rs Same as above for ESDT payment-related test.
Comments suppressed due to low confidence (1)

framework/scenario/src/api/impl_vh/debug_handle.rs:24

  • The _phantom: PhantomData<*const ()> field does not actually prevent DebugHandle from being Send/Sync (raw pointers are Send + Sync), so the comment is currently inaccurate and the extra safety barrier isn’t effective. If you want DebugHandle to be !Send/!Sync, use a phantom marker over a type that is !Send/!Sync (e.g. PhantomData<std::rc::Rc<()>>) or an explicit negative impl where applicable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@andrei-marinica andrei-marinica marked this pull request as ready for review March 30, 2026 11:41
@andrei-marinica andrei-marinica merged commit 5746824 into feat/mdrop Mar 30, 2026
23 checks passed
@andrei-marinica andrei-marinica deleted the threading branch March 30, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants